<!DOCTYPE html>
<html>
<head>
    <base href="#(base)">
    <title>Jweb极速开发 - 登录页</title>
    <link rel="icon" type="image/x-icon" href="/assets/images/favicon.svg"/>
    <link rel="stylesheet" href="/assets/layui/css/layui.css"/>
    <link rel="stylesheet" href="/assets/adai/css/login.css"/>
</head>
<body style="background-color: #046d63;">
<div class="login-bg-cover">
    <img class="login-cat-foot" src="/assets/images/logo.svg" one>
    <img class="login-cat-foot" src="/assets/images/logo.svg" two>
    <img class="login-cat-foot" src="/assets/images/logo.svg" three>
    <img class="login-cat-foot" src="/assets/images/logo.svg" four>
    <img class="login-cat-foot" src="/assets/images/logo.svg" five>
</div>
<div class="login-panel">
    <div class="panel-body">
        <div class="panel-title">Jweb极速开发</div>
        <form class="layui-form layadmin-user-login-body" lay-filter="login_form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" ></label>
                <input type="text" name="userAccount" lay-verify="required|userAccount" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" ></label>
                <input type="password" name="password" lay-verify="required|password" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" ></label>
                        <input type="text" name="vcode" lay-verify="required" maxlength="4" placeholder="图形验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img src="/console/vcode?#(timestamp)" id="vcode" class="layadmin-user-login-codeimg">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn " lay-submit="" lay-filter="login-submit" id="login-submit">登录</button>
            </div>
        </form>
        <div class="support">
            技术支持 jweb.cc
        </div>
    </div>
</div>
<!--  -->
<script src="/assets/lib/jquery/jquery.min.js" type="text/javascript"></script>
<script src="/assets/layui/layui.all.js" type="text/javascript"></script>
<script>
    // 设置全局ajax的错误提示信息
    $.ajaxSetup({
        error: function (e) {
            layer.msg('请求错误： ' + e.statusText + ' (' + e.status + ')', {
                icon: 5,
                time: 5000 //2秒关闭（如果不配置，默认是3秒）
            });
        }
    })
    $(function () {
        var form = layui.form;
        // 自定义表单校验
        form.verify({
            userAccount: [/^.{5,32}$/, '用户名必须5到32位！'],
            password: [/^.{5,32}$/, '登录密码必须5到32位！']
        });
        var $form = $('form'), $btn = $('button'), $vcode = $('#vcode'), $rcode = $('#rcode');
        // 验证码点击事件
        let changeCode = function () {
            $(this)[0].src = '/console/vcode?' + (new Date()).getTime();
        };
        // 验证码点击事件
        $vcode.click(changeCode);

        let $login = $("#login-submit");
        let isLogining = false;
        // 登录表单提交事件
        form.on('submit(login-submit)', function (data) {
            // console.log(data);
            $.ajax({
                url: '/console/login',
                data: data.field,
                type: 'POST',
                dataType: "json",
                beforeSend: function () {
                    isLogining = true;
                    $login.text('正在登录...');
                    $login.addClass("layui-btn-disabled");
                },
                success: function (result) {
                    if (result.success) {
                        window.location.reload(true);
                    } else {
                        layer.msg(result.message, {
                            icon: 5,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        $vcode.trigger('click');
                    }
                },
                complete: function (e, status, b) {
                    isLogining = false;
                    $login.text('登录');
                    $login.removeClass("layui-btn-disabled");
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
